/*
** Copyright (C) 2009 Joshua Brent Marsh <joshua@icub3d.com>
**  
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**  
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**  
*/

/* $Id: utilities.h 53 2009-12-24 20:43:05Z joshua@icub3d.com $ */

#ifndef ICUB3D_UTILITIES_H
#define ICUB3D_UTILITIES_H 1

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <ctype.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdint.h>

#include "map.h"

/* Configuration functions. */
Map * load_config (const char *file, const Map *def);
Map * load_configs (const char *dir, const Map *def);

/* These are used by the get segment. It could return one of these. */
#define ISS_BEGIN      1
#define ISS_END        2
#define ISS_QUOTED     3
#define ISS_NOT_QUOTED 4
#define ISS_FAIL       5

int get_segment (char **pos, char **begin, char **end, 
		 const char *delims, const char *quotes, const char *nulls);

/* Number length functions. */

size_t uint8_t_numlen (const int8_t number, const size_t base);
size_t int8_t_numlen (const uint8_t number, const size_t base,
		      const int include_negative);

size_t uint16_t_numlen (const int8_t number, const size_t base);
size_t int16_t_numlen (const uint8_t number, const size_t base,
		      const int include_negative);

size_t uint32_t_numlen (const int8_t number, const size_t base);
size_t int32_t_numlen (const uint8_t number, const size_t base,
		      const int include_negative);

size_t uint64_t_numlen (const int8_t number, const size_t base);
size_t int64_t_numlen (const uint8_t number, const size_t base,
		      const int include_negative);

size_t snumlen (const size_t number, const size_t base);
size_t ssnumlen (const ssize_t number, const size_t base, 
		 const int include_negative);

/* File functions. */

int mkrdir (const char *pathname, const mode_t mode);

int check_file_exists (const char *path);

int write_file (const char *file_path, const char *data);
char * read_file (const char *file_path);

/* Command functions. */

char * execute_shell_command (const char *command, const char *args[], 
			      const char *input);

int send_email (const char *program, const char *to, const char *from, 
		const char *cc, const char *subject, const char *message, ...);

#endif /* ICUB3D_UTILITIES_H */
